<?php

/**
 *报名成功——送酷炫称号：从小萌萌哒  审核通过，发放小时候萌萌哒奖品
 * User: huy
 * Date: 2016/7/6
 * Time: 17:45
 */
class SendgiftControl extends Control{
    private $time1    = '2016-07-20 00:00:00';   //开始
    private $time2    = '2016-08-01 00:00:00';   //中间投票时间
    private $time3    = '2016-08-31 23:59:59';   //结束
    private $gamecoin = 5000;//投票每一票消耗的游戏币5000
    private $limit    = 10;   //每天最多投10票
    private $level    = 30;//参加活动的等级限制

    //构造函数
    function __construct(){
        parent::__construct();
        $this->actName = '新炫舞宝贝评选';
        load_config('commonMain/onload');
        $this->zone_arr = get_dmz_game_zone();
        load_model(ACT_NAME . '/main');   //自己的main.mod
        $this->model = new MainModel();

        //重新设置活动时间（用于外网、预发布环境）
        if(file_exists(APPLICATION_ROOT . '/config/basic.cfg.php')){
            //include文件的路径，$BasicCFG就存下了.php return 的数组
            $BasicCFG = include_once APPLICATION_ROOT . '/config/basic.cfg.php';
            if(!empty($BasicCFG[YEAR][ACT]['time1']) && !empty($BasicCFG[YEAR][ACT]['time2']) && !empty($BasicCFG[YEAR][ACT]['time3']) && !empty($BasicCFG[YEAR][ACT]['level']) && !empty($BasicCFG[YEAR][ACT]['gamecoin']) && !empty($BasicCFG[YEAR][ACT]['money'])){
                $this->time1    = $BasicCFG[YEAR][ACT]['time1'];
                $this->time2    = $BasicCFG[YEAR][ACT]['time2'];
                $this->time3    = $BasicCFG[YEAR][ACT]['time3'];
                $this->level    = $BasicCFG[YEAR][ACT]['level'];
                $this->gamecoin = $BasicCFG[YEAR][ACT]['gamecoin'];
                $this->money    = $BasicCFG[YEAR][ACT]['money'];
            }
        }
    }

    public function sendgift($uin){
        //$uin = $_GET['uin'];
        //uin in ({$uin})??    1.是：in ？   2.没有限定  zoneid
        $list = $this->model->get_item('bbpx2016_userinfo', "`uin`,`zone_id`,`sex`,`status`", " uin in ({$uin}) and award=0");
        if(!empty($list)){
            foreach($list as $row){
                if($row['status'] == 5){
                     //审核通过，发放小时候萌萌哒奖品3600025b
                    $row['sex'] == 1 && $status = $this->model->sendGameItem($row['uin'], $row['zone_id'], '3600025b', 1, 2147483647);
                    $row['sex'] == 2 && $status = $this->model->sendGameItem($row['uin'], $row['zone_id'], '3600025b', 1, 2147483647);
                    $this->model->update_data('bbpx2016_userinfo', array(), "uin={$row['uin']} and zone_id={$row['zone_id']} limit 1", "award={$status}");
                }
            }
            $go = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script language="javascript">alert("审核成功，发奖成功！");self.location="http://dmzcms.xx5.com/dmz_bbs_admin/index.php?c=admin-2016-bbpx2016&a=user_manage&type=1";</script>';
            echo $go;
        }else{
            $go = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script language="javascript">alert("审核成功，发奖出错！");self.location="http://dmzcms.xx5.com/dmz_bbs_admin/index.php?c=admin-2016-bbpx2016&a=user_manage&type=1";</script>';
            echo $go;
        }
    }
}